package com.rich.service.impl;

import java.util.List;

import com.rich.dao.CategoryDao;
import com.rich.dao.impl.CategoryDaoImpl;
import com.rich.domain.Category;
import com.rich.service.CategoryService;
import com.rich.utils.BeanFactory;
import com.rich.utils.JsonUtil;

public class CategoryServiceImpl implements CategoryService {

	CategoryDao cd = (CategoryDao) BeanFactory.getBean("CategoryDao");
	
	/**
	 * 查询商品分类
	 * 返回list集合
	 */
	@Override
	public List<Category> findList() throws Exception {
		return cd.findAll();
	}
	
	/**
	 * 查找商品分类
	 * 返回json字符串
	 */
	@Override
	public String findAll() throws Exception {
		//查找所有分类
		List<Category> categories = findList();
		//将list转成json字符串
		if(categories != null && categories.size()>0) {
			return JsonUtil.list2json(categories);
		}
		return null;
	}

	/**
	 * 保存分类
	 */
	@Override
	public void save(Category category) throws Exception {
		cd.save(category);
	}

	/**
	 * 修改分类信息
	 */
	@Override
	public void update(String cid,String cName) throws Exception {
		cd.update(cid,cName);
	}

	/**
	 * 删除某个分类信息
	 */
	@Override
	public void remove(String cid) throws Exception {
		cd.remove(cid);
	}


}
